import { configureStore } from "@reduxjs/toolkit";
import userReducer from "@/store/modules/userStore";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage"; // defaults to localStorage for web

const persistConfig = {
  key: "user",
  storage,
}

const persistedUserReducer = persistReducer(persistConfig, userReducer);


const store = configureStore({
  reducer: {
    user: persistedUserReducer,
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: {
        // 仅忽略redux-persist相关action的序列化检查
        ignoredActions: ['persist/PERSIST', 'persist/REHYDRATE', 'persist/REGISTER']
      },
    }),
});

// 创建持久化存储器
export const persistor = persistStore(store);

export default store;
